/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wii.elpro.dao.hb;

import com.wii.elpro.dao.HibernateUtil;
import com.wii.elpro.dao.QuotationDAOInterface;
import com.wii.elpro.entity.Cabang;
import com.wii.elpro.entity.Quotation;
import com.wii.elpro.entity.User;
import java.util.List;
import org.hibernate.Session;

/**
 *
 * @author hendro
 */
public class QuotationDAOImpl extends DAOGenericImpl implements QuotationDAOInterface {

    public Quotation getQuotation(long id) throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try {
            return (Quotation) session.load(Quotation.class, id);
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<Quotation> getQuotations() throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try {
            return session.createQuery("SELECT q FROM Quotation q").list();
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<Quotation> getQuotations(int status) throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try {
            return session.createQuery("SELECT q FROM Quotation q WHERE q.status=:input")
                    .setParameter("input", status).list();
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<Quotation> getQuotations(Cabang cabang, int status) throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try {
            return session.createQuery("SELECT q FROM Quotation q WHERE q.status=:input AND q.spdcf.inquery.cabang=:input2")
                    .setParameter("input", status)
                    .setParameter("input2", cabang).list();
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<Quotation> getQuotations(User sales, int status) throws Exception {
       HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try {
            return session.createQuery("SELECT q FROM Quotation q WHERE q.status=:input AND q.spdcf.inquery.sales=:input2")
                    .setParameter("input", status)
                    .setParameter("input2", sales).list();
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<Quotation> getQuotations(String noQuotation) throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try {
            return session.createQuery("SELECT q FROM Quotation q WHERE q.noQuotation=:input").setParameter("input", noQuotation).list();
        } catch (Exception ex) {
            throw ex;
        }
    }
}
